<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>个人信息</title>
    <link rel="stylesheet" href="layui/css/layui.css">
</head>
<body class="layui-layout-body">
<div style="margin-top: 50px;>
<!-- 示例-970 -->
<ins class="adsbygoogle" style="display:inline-block;width:970px;height:90px" data-ad-client="ca-pub-6111334333458862" data-ad-slot="3820120620"></ins>

<fieldset class="layui-elem-field layui-field-title" style="margin-top: 50px;">
    <legend>个人信息</legend>
</fieldset>

<form class="layui-form" action="" lay-filter="example" >


     <div class="layui-form-item">
        <label class="layui-form-label">工号<span id="id" style="visibility: hidden"></span></label>
        <div class="layui-input-block">
            <input type="text" id="account" name="account" lay-verify="account" autocomplete="off" placeholder="请输入工号" class="layui-input">
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">密码</label>
        <div class="layui-input-block">
            <input type="text" name="pwd" placeholder="请输入密码" autocomplete="off" class="layui-input">
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">姓名</label>
        <div class="layui-input-block">
            <input type="text" name="name" autocomplete="off" placeholder="请输入" class="layui-input">
        </div>
    </div>

    <div class="layui-form-item">
        <label class="layui-form-label">电话</label>
        <div class="layui-input-block">
            <input type="text" name="phone" autocomplete="off" placeholder="请输入" class="layui-input">
        </div>
    </div>


    <div class="layui-form-item">
        <div class="layui-input-block">
<!--            <button type="button" class="layui-btn layui-btn-normal" id="LAY-component-form-setval">赋值</button>-->
            <button type="button" class="layui-btn layui-btn-normal" id="LAY-component-form-getval">提交</button>
<!--            <button type="submit" class="layui-btn" lay-submit="" lay-filter="demo1">立即提交</button>-->
        </div>
    </div>
</form>
<script src="contance.js"></script>
<script src="layui/layui.all.js"></script>
<!-- 注意：如果你直接复制所有代码到本地，上述js路径需要改成你本地的 -->
<script>
    layui.use(['form', 'layedit', 'laydate',"upload",], function(){
        var form = layui.form
            ,layer = layui.layer
            ,layedit = layui.layedit
            ,upload = layui.upload
            ,laydate = layui.laydate;

        //日期
        laydate.render({
            elem: '#date'
        });
        laydate.render({
            elem: '#date1'
        });

        //创建一个编辑器
        var editIndex = layedit.build('LAY_demo_editor');

        //自定义验证规则
        form.verify({
            account: function(value){
                if(value.length < 5){
                    return '账号至少得5个字符啊';
                }
            }
            ,pass: [
                /^[\S]{6,12}$/
                ,'密码必须6到12位，且不能出现空格'
            ]
            ,content: function(value){
                layedit.sync(editIndex);
            }
        });

        //监听指定开关
        form.on('switch(switchTest)', function(data){
            layer.msg('开关checked：'+ (this.checked ? 'true' : 'false'), {
                offset: '6px'
            });
            layer.tips('温馨提示：请注意开关状态的文字可以随意定义，而不仅仅是ON|OFF', data.othis)
        });

        layui.jquery.ajax({
            url:baseurl+"/getTercherInfo",
            data:{'id':layui.data('user').id},
            type:"Post",
            success:function(result){
                form.val('example', {
                    "name": result.data.name,
                    "account": result.data.account,
                    "pwd": result.data.pwd,
                    "phone": result.data.phone
                });

            },
            error:function(result){
                // $.messager.alert('错误',result.msg);
            }
        });

        //表单取值
        layui.$('#LAY-component-form-getval').on('click', function(){
            var data = form.val('example');


                layui.jquery.ajax({
                    url:baseurl+"/upTercher",
                    data:{ "name": data.name,
                        "account": data.account,
                        "pwd": data.pwd,
                        "phone": data.phone,id:layui.data('user').id},
                    type:"Post",
                    success:function(result){
                        console.log(result);
                        layer.msg(result.msg);
                        layui.data('user', {
                            key: 'name'
                            ,value: data.name
                        });
                        // location.reload(); //删除成功后再刷新
                    },
                    error:function(result){
                        // $.messager.alert('错误',result.msg);
                    }
                });


        });

    });
</script>

</body>
</html>